package com.masterclient.app.modules.order;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.eoner.baselibrary.bean.order.StorageOrderDetailData;
import com.eoner.baselibrary.bean.order.StorageOrderDetailProductItemBean;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.BaseActivity;
import com.masterclient.app.R;
import com.masterclient.app.modules.order.contract.StorageOrderDetailContract;
import com.masterclient.app.modules.order.contract.StorageOrderDetailPresenter;
import com.masterclient.app.widget.TitlebarView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @auther hjian
 * @date 2020/10/19.
 */
@Route(path = AroutePath.STORAGE_ORDER_DETAIL_ACTIVITY)
public class StorageOrderDetailActivity extends BaseActivity<StorageOrderDetailPresenter> implements StorageOrderDetailContract.View {

    @BindView(R.id.storage_order_detail_bar)
    TitlebarView storageOrderDetailBar;
    @BindView(R.id.storage_order_detail_notice)
    TextView storageOrderDetailNotice;
    @BindView(R.id.storage_order_detail_notice_layout)
    LinearLayout storageOrderDetailNoticeLayout;
    @BindView(R.id.storage_order_detail_name)
    TextView storageOrderDetailName;
    @BindView(R.id.storage_order_detail_no)
    TextView storageOrderDetailNo;
    @BindView(R.id.storage_order_detail_time)
    TextView storageOrderDetailTime;
    @BindView(R.id.storage_order_detail_recycler)
    LinearLayout storageOrderDetailRecycler;
    @BindView(R.id.storage_order_detail_scroll)
    NestedScrollView storageOrderDetailScroll;

    @Autowired(name = "order_no")
    String orderNo;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_storage_order_detail);
        ButterKnife.bind(this);
        ARouter.getInstance().inject(this);

        storageOrderDetailBar.setOnViewClick(new TitlebarView.onViewClick() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });

        mPresenter.getDetailData(orderNo);

    }

    @Override
    public void showFailure(String msg) {
        ToastUtil.showToast(msg);
    }

    @Override
    public void showData(StorageOrderDetailData detailData) {
        storageOrderDetailScroll.setVisibility(View.VISIBLE);
        if (TextUtils.isEmpty(detailData.getTop_tips())){
            storageOrderDetailNoticeLayout.setVisibility(View.GONE);
        }else {
            storageOrderDetailNoticeLayout.setVisibility(View.VISIBLE);
            storageOrderDetailNotice.setText(detailData.getTop_tips());
        }

        storageOrderDetailName.setText(new StringBuffer("购买经销商: ").append(detailData.getSeller_name()));
        storageOrderDetailNo.setText(new StringBuffer("保管单号：").append(detailData.getOrder_no()));
        storageOrderDetailTime.setText(new StringBuffer("保管时间：").append(detailData.getShow_at()));

        storageOrderDetailRecycler.removeAllViews();
        for (StorageOrderDetailProductItemBean itemBean : detailData.getProducts()) {
            View view = View.inflate(this,R.layout.item_storage_order_detail,null);
            ((TextView)view.findViewById(R.id.item_storage_order_detail_name)).setText(
                    new StringBuffer(itemBean.getName()).append("-").append(itemBean.getAttribute_text()));
            ((TextView)view.findViewById(R.id.item_storage_order_detail_num)).setText(itemBean.getCustody_qty());
            storageOrderDetailRecycler.addView(view);
        }

    }


}
